package com.itheima.service.Impl;

import com.itheima.mapper.ReportMapper;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapper reportMapper;
    /**
     * 查询员工性别数据
     * @return
     */
    public List<Map> getEmpGenderData() {
        List<Map> gendeList=reportMapper.getEmpGenderData();
        return gendeList;
    }

    /**
     * 查询各个职位的员工人数
     * @return
     */
    public JobOption getEmpJobData() {
        List<Map<String, Object>> list=reportMapper.countEmpJobData();
        List<Object> jobList = list.stream().map(datamap -> datamap.get("pos")).toList();
        List<Object> dataList = list.stream().map(datamap -> datamap.get("num")).toList();
        JobOption jobOption=new JobOption(jobList,dataList);
        return jobOption;
    }

    /**
     * 学员学历统计
     *
     * @return
     */
    public List<Map<String, Object>> getStuDegreeData() {
        List<Map<String,Object>> stuDegreeList=reportMapper.getStuDegreeData();
        return stuDegreeList;
    }

    /**
     * 班级人数统计
     * @return
     */
    public ClazzOption getStuCountData() {
        List<Map<String,Object>> stuCountList=reportMapper.getStuCountData();
        List<Object> clazzList = stuCountList.stream().map(datamap -> datamap.get("name")).toList();
        List<Object> dataList = stuCountList.stream().map(datamap -> datamap.get("value")).toList();
        ClazzOption clazzOption=new ClazzOption(clazzList,dataList);
        return clazzOption;
    }
}
